package application.view.viewComponent 
{
	import flash.display.Bitmap;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import ginger.geom.RectangleShape;
	import ginger.ui.simpleControls.SimpleBrightnessButton;
	import caurina.transitions.Tweener;
	/**
	 * ...
	 * @author Ning
	 */
	public class TipView extends TranView
	{
		private var _tipBtn:SimpleBrightnessButton;
		private var _tipMC:MovieClip;
		private var _whiteSprite:Sprite;;
		public function TipView() 
		{
			_tipBtn = new SimpleBrightnessButton(new Bitmap(AppGlobal.MATERIAL_RESOURCES.tipIconBmpData));
			addChild(_tipBtn);
			_tipBtn.addEventListener(MouseEvent.CLICK, onClick);
			
			_tipMC = AppGlobal.MATERIAL_RESOURCES.tipMC;
			if (_tipMC['exitBtn'])
			    _tipMC['exitBtn'].addEventListener(MouseEvent.CLICK, onExit);
			
			_whiteSprite = new Sprite();
		}
		
		private function onClick(evt:MouseEvent):void
		{
		    AppGlobal.STAGE.addChild(_whiteSprite);
			AppGlobal.STAGE.addEventListener(Event.RESIZE, onResize);
			AppGlobal.STAGE.addEventListener(MouseEvent.MOUSE_WHEEL, onExit);
			onResize();
			
			AppGlobal.STAGE.addChild(_tipMC);
			_tipMC.y = -_tipMC.height;
			Tweener.removeTweens(_tipMC);
		    Tweener.addTween(_tipMC, { time:.5, y:(AppGlobal.STAGE.stageHeight - _tipMC.height) / 2 } );
		}
		private function onResize(evt:Event=null):void
		{
			_whiteSprite.graphics.clear();
			_whiteSprite.graphics.beginFill(0xffffff,.5);
			_whiteSprite.graphics.drawRect(0, 0, AppGlobal.STAGE.stageWidth, AppGlobal.STAGE.stageHeight);
			_whiteSprite.graphics.endFill();
			
			_tipMC.x = (AppGlobal.STAGE.stageWidth - _tipMC.width) / 2;
			_tipMC.y = (AppGlobal.STAGE.stageHeight - _tipMC.height) / 2;
		}
		
		private function onExit(evt:MouseEvent = null):void
		{
			AppGlobal.STAGE.removeEventListener(Event.RESIZE, onResize);
			AppGlobal.STAGE.removeEventListener(MouseEvent.MOUSE_WHEEL, onExit);
			
			
			if(AppGlobal.STAGE.contains(_whiteSprite))
			    AppGlobal.STAGE.removeChild(_whiteSprite);
			Tweener.addTween(_tipMC, { time:.5, y: -_tipMC.height, onComplete:onComplete } );
			function onComplete():void
			{
				if(AppGlobal.STAGE.contains(_tipMC))
			        AppGlobal.STAGE.removeChild(_tipMC);
			}
		}   
	}
}